package com.wuzf.demo.demo.bootstrap;


import com.wuzf.demo.demo.condition.ConditionalOnSystemProperty;
import org.springframework.boot.WebApplicationType;
import org.springframework.boot.builder.SpringApplicationBuilder;
import org.springframework.context.ConfigurableApplicationContext;
import org.springframework.context.annotation.Bean;


public class ConditionOnSystemPropertyBootstrap {

    @Bean
    // 当条件匹配的时候返回Bean的内容
    @ConditionalOnSystemProperty(name = "user.name", value = "Administrator")
    public String helloWorld() {
        return "hello world 2021 hhhh";
    }

    public static void main(String[] args) {

        ConfigurableApplicationContext context = new SpringApplicationBuilder(ConditionOnSystemPropertyBootstrap.class)
                .web(WebApplicationType.NONE)
                .run(args);

        String result = context.getBean("helloWorld", String.class);
        System.out.println("helloWorld bean:" + result);

        context.close();
    }

}
